package com.ybkj.daijia.server.interceptors;

import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * Copyright (C) , 2012-2018 , 四川小咖科技有限公司
 *
 * @author xu
 * @version 1.0
 * @Date
 * @since 1.0.0
 */
public class MethodInterceptor extends HandlerInterceptorAdapter {

    private static ThreadLocal<Method> methodThreadLocal = new ThreadLocal<>();

    public static Method getMethod() {
        return methodThreadLocal.get();
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
        Object handler)
        throws Exception {
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            methodThreadLocal.set(handlerMethod.getMethod());
        }
        return true;
    }
}
